﻿@using ABC.Controllers.ViewModels
@model ABC.Controllers.ViewModels.My.MyKvViewModel
@{
    ViewBag.Title = "Комиссионное вознаграждение";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
    var pagesize = Request.Params["pagesize"];
    var company = Request.Params["company"];
    var product = Request.Params["product"];
}
<script type="text/javascript">
    function Filter() {
        location.href = '@Url.Action("Kv", "Cabinet")?' + ($("#Company").val() ? "company=" + $("#Company").val() : "") + ($("#Product").val() ? "&product=" + $("#Product").val() : "") + ($("#PageSize").val() != '@Model.ListForPageSize.First().Value' ? "&pagesize=" + $("#PageSize").val() : "");
    }
    function ResetFilter() {
        location.href = '@Url.Action("Kv", "Cabinet", new { page = 1 })';
    }


</script>
<div class="row-fluid">
    <!--// Левая колонка -->
    @{Html.RenderPartial("_SectionCabinetMenu", new BaseViewModel());}
    <!--// Правая колонка -->
    <div class="span9">
        <div class="page-header">
            <h2>
                Комиссионное вознаграждение</h2>
        </div>
        <div class="row-fluid">
            <div class="span3">
                <div class="control-group">
                    <label class="control-label" for="Company">
                        Компания</label>
                    <div class="controls">
                        @Html.DropDownListFor(x => x.Company, Model.ListForCompany, "Все компании", new { @class = "input-medium" })
                    </div>
                </div>
            </div>
            <div class="span3">
                <div class="control-group">
                    <label class="control-label" for="product">
                        Продукт</label>
                    <div class="controls">
                        @Html.DropDownListFor(x => x.Product, Model.ListForProduct, "Все продукты", new { @class = "input-medium" })
                    </div>
                </div>
            </div>
            <div class="span3">
            </div>
            <div class="span3">
                <div class="control-group">
                    <label class="control-label" for="phone-01">
                        Фильтр</label>
                    <div class="controls">
                        <div class="btn-group">
                            <button type="button" class="btn" onclick="Filter();">
                                Применить</button>
                            <button class="btn" rel="tooltip" data-original-title="Сбросить фильтр" onclick="ResetFilter();">
                                <i class="icon-refresh"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <table class="table table-bordered" id="setka-kv">
            <thead>
                <tr>
                    <th rowspan="2">
                        Вид
                    </th>
                    <th colspan="2">
                        Комиссия
                    </th>
                    <th rowspan="2">
                        Комментарий
                    </th>
                </tr>
                <tr>
                    <th>
                        А-1
                    </th>
                    <th>
                        А-2
                    </th>
                </tr>
            </thead>
            <tbody>
                @for (var i = 0; i < Model.PolicyItems.Count; i++)
                {
                    if (i == 0)
                    {
                    <tr>
                        <th colspan="100%">
                            <a href="@Url.Action("FormPartner", "Admin", new { id = Model.PolicyItems[i].Company })" title="Открыть персональную страницу страховой компании"
                                target="_blank">@Model.PolicyItems[i].CompanyName</a>
                        </th>
                    </tr>
                    }
                    else if (Model.PolicyItems[i].Company != Model.PolicyItems[i - 1].Company)
                    {
                    <tr>
                        <th colspan="100%">
                            <a href="@Url.Action("FormPartner", "Admin", new { id = Model.PolicyItems[i].Company })" title="Открыть персональную страницу страховой компании"
                                target="_blank">@Model.PolicyItems[i].CompanyName</a>
                        </th>
                    </tr>
                    }
                    if (i == 0)
                    {
                    <tr>
                        <td rowspan="@Model.PolicyItems.Count(x => x.Company == Model.PolicyItems[i].Company && x.TypeOfInsurance == Model.PolicyItems[i].TypeOfInsurance)">
                            <span>@Model.PolicyItems[i].TypeOfInsuranceName</span>
                        </td>
                        <td>
                            @(!string.IsNullOrEmpty(Model.PolicyItems[i].Rewards.FirstOrDefault(x => x.Name == "А-1").Value) ? Model.PolicyItems[i].Rewards.FirstOrDefault(x => x.Name == "А-1").Value + "%" : "")
                        </td>
                        <td>
                            @(!string.IsNullOrEmpty(Model.PolicyItems[i].Rewards.FirstOrDefault(x => x.Name == "А-2").Value) ? Model.PolicyItems[i].Rewards.FirstOrDefault(x => x.Name == "А-2").Value + "%" : "")
                        </td>
                        <td>
                            @Model.PolicyItems[i].Comment
                        </td>
                    </tr>
                    }
                    else if (Model.PolicyItems[i].TypeOfInsurance == Model.PolicyItems[i - 1].TypeOfInsurance && Model.PolicyItems[i].Company == Model.PolicyItems[i - 1].Company)
                    {
                    <tr>
                        <td>
                            @(!string.IsNullOrEmpty(Model.PolicyItems[i].Rewards.FirstOrDefault(x => x.Name == "А-1").Value) ? Model.PolicyItems[i].Rewards.FirstOrDefault(x => x.Name == "А-1").Value + "%" : "")
                        </td>
                        <td>
                            @(!string.IsNullOrEmpty(Model.PolicyItems[i].Rewards.FirstOrDefault(x => x.Name == "А-2").Value) ? Model.PolicyItems[i].Rewards.FirstOrDefault(x => x.Name == "А-2").Value + "%" : "")
                        </td>
                        <td>
                            @Model.PolicyItems[i].Comment
                        </td>
                    </tr>
                    }
                    else
                    {
                    <tr>
                        <td rowspan="@Model.PolicyItems.Count(x => x.Company == Model.PolicyItems[i].Company && x.TypeOfInsurance == Model.PolicyItems[i].TypeOfInsurance)">
                            <span>@Model.PolicyItems[i].TypeOfInsuranceName</span>
                        </td>
                        <td>
                            @(!string.IsNullOrEmpty(Model.PolicyItems[i].Rewards.FirstOrDefault(x => x.Name == "А-1").Value) ? Model.PolicyItems[i].Rewards.FirstOrDefault(x => x.Name == "А-1").Value + "%" : "")
                        </td>
                        <td>
                            @(!string.IsNullOrEmpty(Model.PolicyItems[i].Rewards.FirstOrDefault(x => x.Name == "А-2").Value) ? Model.PolicyItems[i].Rewards.FirstOrDefault(x => x.Name == "А-2").Value + "%" : "")
                        </td>
                        <td>
                            @Model.PolicyItems[i].Comment
                        </td>
                    </tr>
                    }
                }
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="100%">
                        <div class="table-toolbar">
                            <div class="quant-item pull-left">
                                @Html.DropDownListFor(x => x.PageSize, Model.ListForPageSize, new { @class = "input-mini", onchange = "Filter();" })
                                <span class="help-inline">записей на странице</span>
                            </div>
                            <div class="pagination pagination-right">
                                <ul>
                                    @Html.Paging(Model.PageNumber, Model.PageCount, i => Url.Action("Kv", "Cabinet", new { page = i, pagesize, company, product }))
                                </ul>
                            </div>
                        </div>
                    </td>
                </tr>
            </tfoot>
        </table>
        <div class="btn-toolbar">
            <button class="btn">
                Выгрузить в PDF</button>
        </div>
    </div>
</div>
